package AwsSNS;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.sns.AmazonSNS;
import com.amazonaws.services.sns.AmazonSNSClient;
import com.amazonaws.services.sns.model.*;
import java.util.List;

public class SNSTeste {

    public static final String ACCESS_KEY = "AKIAJICRH6ZVS7ENHQMA";
    public static final String SECRET_KEY = "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";

    public static void main(String[] args) {

        AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
        AmazonSNS sns = new AmazonSNSClient(credentials);

        //lista os topicos existentes do SNS
        ListTopicsResult topicos = new ListTopicsResult();
        topicos = sns.listTopics();

        List<Topic> lstTopic = topicos.getTopics();

        for (Topic topic : lstTopic) {
            System.out.println("TOPICO DO SNS: " + topic.getTopicArn());

//            ListSubscriptionsResult listResult = new ListSubscriptionsResult();
//            listResult = sns.listSubscriptions();
//            List<Subscription> listSubscricao = listResult.getSubscriptions();
//
//            for (Subscription subscription : listSubscricao) {
//                System.out.println("SUBSCRICAO LOCALIZADA: " + subscription.getEndpoint());
//            }

            ListSubscriptionsByTopicRequest listSubsRequest = new ListSubscriptionsByTopicRequest(topic.getTopicArn());
            ListSubscriptionsByTopicResult listaIncritosTopico = sns.listSubscriptionsByTopic(listSubsRequest);
            List<Subscription> inscritosTopico = listaIncritosTopico.getSubscriptions();

            for (Subscription subscription : inscritosTopico) {
                System.out.println("INSCRITOS NO TOPICO: " + subscription.getSubscriptionArn());
            }

        }
    }
}
